Divisibility and Prime Numbers
Understanding divisibility and prime numbers is essential in number theory, with applications in cryptography, algorithm optimization, and more.
Divisibility
Divisibility rules help quickly determine whether a number is divisible by another without performing full division. Here are some basic divisibility rules:
- Divisibility by 2: A number is divisible by 2 if its last digit is even.
- Divisibility by 3: A number is divisible by 3 if the sum of its digits is divisible by 3.
def is_divisible_by_3(n):
return sum(map(int, str(n))) % 3 == 0 - Divisibility by 5: A number is divisible by 5 if its last digit is 0 or 5.
def is_divisible_by_5(n):
return str(n)[-1] in ('0', '5') - Divisibility by 9: A number is divisible by 9 if the sum of its digits is divisible by 9.
def is_divisible_by_9(n):
return sum(map(int, str(n))) % 9 == 0 - Divisibility by 10: A number is divisible by 10 if it ends in 0.
Examples
- Is 123 divisible by 3? Sum of digits: 1 + 2 + 3 = 6, which is divisible by 3, so 123 is also divisible by 3.
- Is 145 divisible by 5? Last digit is 5, so it is divisible by 5.
Prime Numbers
A prime number is a natural number greater than 1 that has no divisors other than 1 and itself.
Properties of Prime Numbers
- Uniqueness: Each natural number greater than 1 is either a prime itself or can be factored uniquely into prime numbers (Fundamental Theorem of Arithmetic).
- Infinitude: There are infinitely many prime numbers.
Prime Checking Algorithms
- Trial Division: Check if the number is divisible by any number up to its square root.
- Sieve of Eratosthenes: An efficient way to find all primes up to a certain limit.
Prime-Related Concepts
- Co-primes: Two numbers are co-prime if their greatest common divisor (GCD) is 1.
- Prime Factorization: Breaking down a number into the product of prime numbers. For example, 60 = 2 * 2 * 3 * 5.
Prime Number Theorems
- Prime Density: The density of prime numbers decreases as numbers get larger.
- Approximation: The Prime Number Theorem approximates the number of primes less than a given number as .
Practice Problems
- Check If Number Is Prime
- Prime Factorization
- Sieve of Eratosthenes Implementation
- Find GCD of Array (Co-primes)
By understanding divisibility rules and the properties of prime numbers, you can solve complex problems related to number theory more efficiently.